package com.lt.bcra.controller.dictionary;


import com.lt.bcra.controller.questionnaire.BcraDefaultValueController;
import com.lt.bcra.entity.BcraCategory;
import com.lt.bcra.entity.BcraDefaultValue;
import com.lt.bcra.entity.BcraFamilyHistory;
import com.lt.bcra.exception.BaseException;
import com.lt.bcra.result.ResponseEnum;
import com.lt.bcra.result.ResultData;
import com.lt.bcra.service.BcraCategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author LuoTian
 * @since 2022-05-30
 */
@Api(tags = "字典种类表")
@CrossOrigin //跨域可以前端配置
@RestController
@RequestMapping("/bcra/category")
public class BcraCategoryController {

    private static Logger log = LoggerFactory.getLogger(BcraCategoryController.class);

    @Autowired
    BcraCategoryService bcraCategoryService;


    @GetMapping("/getCategories")
    @ApiOperation("查看字典种类表")
    public ResultData list() throws BaseException {
        if (log.isDebugEnabled()) log.debug("查看字典种类表 BcraCategoryController");

        List<BcraCategory> list = bcraCategoryService.list();
        if (list == null){
            throw new BaseException(ResponseEnum.SELECT_DATA_ERROR);
        }
        return ResultData.getResult(list);
    }

    @DeleteMapping("/deleteCategory/{id}")
    @ApiOperation("删除字典种类表")
    @ApiParam(value = "id")
    public ResultData delete(@PathVariable Integer id) throws BaseException{
        if (log.isDebugEnabled()) log.debug("删除字典种类 BcraCategoryController");

        return bcraCategoryService.deleteCategory(id);
    }

    @PostMapping("/creatCategory")
    @ApiOperation("创建字典种类表")
    @ApiParam(value = "bcraCategory")
    public ResultData creatNew(@RequestBody BcraCategory bcraCategory) throws BaseException {
        if (log.isDebugEnabled()) log.debug("创建字典种类表 BcraCategoryController");

        return bcraCategoryService.saveCategory(bcraCategory);
    }
}

